package com.situ.boot.controller;


import com.situ.boot.entity.User;
import com.situ.boot.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Slf4j
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/hello.action")
    @ResponseBody
    public String hello() {
        System.out.println("hello");
        log.debug("hello SpringBoot");
        return "Hello SpringBoot!";
    }

    @RequestMapping("/getLoginPage")
    public String getLoginPage () {
        log.debug("getLoginPage");
        return "/login";
    }

    @RequestMapping("/selectAll")
    @ResponseBody
    public List<User> selectAll() {
        List<User> list = userMapper.selectAll();
        return list;
    }

    @RequestMapping("/getUserListPage")
    public String getUserListPage(Model model) {
        List<User> list = userMapper.selectAll();
        model.addAttribute("list", list);

        return "user_list";
    }
}
